package com.zxy.mapper;

import com.zxy.dto.PersonCount;
import com.zxy.dto.SexCount;
import com.zxy.entity.Student;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author Zxy
 * @since 2021-05-11
 */
public interface StudentMapper extends BaseMapper<Student> {

    /**
     * 审核学生状态
     *
     * @param stuId  学生id
     * @param status 状态
     * @return int
     */
    int stuExam(@Param("stuId") Integer stuId, @Param("status") Integer status);

    /**
     * 统计男女生人数
     *
     * @return The {@link SexCount}
     */
    @Select("select sex,count(*) as num from student s1\n" +
            "group by sex")
    List<SexCount> countBySexCount();

    /**
     * 统计总人数
     *
     * @return The {@link com.zxy.dto.PersonCount}
     */
    @Select("select count(*) count from student")
    PersonCount personCount();

    /**
     * 统计18到24之间的人数占比
     *
     * @return The {@link com.zxy.dto.PersonCount}
     */
    @Select("select count(*) count from student\n" +
            "where age BETWEEN 18 and 24")
    PersonCount eighteenToTwentyFour();

    /**
     * 更新学生一卡通卡号
     *
     * @param card 卡号
     * @return 受影响行数
     */
    @Update("update student set card=#{card} where idCard=#{idCard}")
    int updateCardInfo(String idCard, String card);
}
